package com.itheima.service.impl;

import com.itheima.dao.AccountDao;
import com.itheima.pojo.Account;
import com.itheima.service.AccountService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = false,propagation = Propagation.REQUIRED)
public class AccountServiceImpl implements AccountService {
    private AccountDao accountDao;
    public boolean transfer(String outName, String inName, float money) {
        //查询转出账户信息
        Account transferOutName = accountDao.findAccountByName(outName);
        //查询转入账户信息
        Account transferInName = accountDao.findAccountByName(inName);
        //转账业务
        //转入账户加钱
        int add = accountDao.transferIn(outName, money);
        //转出账户减钱
        int reduce = accountDao.transferTo(inName, money);
        return add>0&&reduce>0;
    }

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao=accountDao;
    }
}
